//
//  HMRetweetView.swift
//  Weibo
//
//  Created by ZhuDong on 16/5/25.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit
class HMRetweetView: UIView {
    var topConstraint: Constraint?
    var statusViewModel: HMStatusViewModel?{
        didSet{
            nameLabel.attributedText = statusViewModel?.retweetAttributeString
            let pictures = statusViewModel?.status?.retweeted_status?.pic_urls
            pictureView.pictures = pictures
            
            topConstraint?.uninstall()
            if pictures?.count > 0 {
                self.snp_updateConstraints(closure: { (make) in
                   self.topConstraint = (make.bottom.equalTo(pictureView).offset(StatusCellMargin)).constraint
                    pictureView.hidden = false
                })
            }else{
                self.snp_makeConstraints(closure: { (make) in
                    self.topConstraint = (make.bottom.equalTo(nameLabel).offset(StatusCellMargin)).constraint
                     pictureView.hidden = true
                })
            }
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addSubview(self.nameLabel)
        addSubview(pictureView)
        nameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(StatusCellMargin)
            make.right.equalTo(self).offset(-StatusCellMargin)
            make.left.equalTo(self).offset(StatusCellMargin)
            
        }
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp_bottom)
            make.left.equalTo(nameLabel)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        self.snp_makeConstraints { (make) in
        self.topConstraint = (make.bottom.equalTo(pictureView).offset(StatusCellMargin)).constraint
        }
    }
    /*
    lazy var nameLabel: UILabel = UILabel(title: "sdfsfdf", font: UIFont.systemFontOfSize(14), textColor: UIColor.blackColor(), align: .Left)
 */
    lazy var nameLabel: YYLabel = {
        let yyl = YYLabel()
        yyl.numberOfLines = 0
        yyl.font = originalContentLabelFont
        yyl.preferredMaxLayoutWidth = ScreenWidth - 2 * StatusCellMargin
        return yyl
    }()
    
    lazy var pictureView: HMPictureView = HMPictureView()
}
